package com.jboost.modules.app.controller;

import cn.hutool.core.bean.BeanUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.jboost.common.api.vo.Result;
import com.jboost.common.constant.enums.OpEnum;
import com.jboost.common.util.HttpRestUtils;
import com.jboost.modules.app.constant.BaseResult;
import com.jboost.modules.app.util.JwtUtil;
import com.jboost.modules.app.constant.TokenDto;
import com.jboost.modules.app.util.StrategyFactory;
import com.jboost.modules.system.constant.ConnectEnum;
import com.jboost.modules.system.constant.DepartEnum;
import com.jboost.modules.system.entity.SysUser;
import io.jsonwebtoken.Claims;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.*;
import java.util.concurrent.CompletableFuture;

@Api(tags = "客户管理")
@RestController
@RequestMapping("/xiaoman")
@Slf4j
@AllArgsConstructor
public class XmController {



    StrategyFactory strategyFactory;

    @PostMapping(value = "/push")
    @ApiOperation(value = "数据推送", notes = "数据推送")
    public Result<Boolean> push(@RequestBody JSONObject jsonObject, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception {
       CompletableFuture.runAsync( () -> {
           try {
               strategyFactory.invokeStrategy(jsonObject,"XmAllureOrderBackQuery");
           } catch (Exception e) {
               throw new RuntimeException(e);
           }
       });
        return Result.OK();
    }


    @GetMapping(value = "/test")
    @ApiOperation(value = "数据同步", notes = "数据同步")
    public Result<BaseResult> test() throws Exception {
        return Result.OK((BaseResult) strategyFactory.invokeStrategy(null,"XmUserQuery"));
    }


}
